package com.polly.esphwevent.repository;

import org.springframework.data.redis.core.RedisOperations;
import org.springframework.data.redis.core.SetOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @author liqin@nd.com.cn
 * @version V1.0
 * @title: SetCacheDao
 * @description: TODO(用一句话描述该文件做什么)
 * @date: 2019/3/27 20:34
 */
@Repository
public class SetCacheDao<K,V> {

    @Resource
    private SetOperations<K, V> setOps;


    public Long add(K key, V... values) {
        return setOps.add(key, values);
    }


    public Set<V> difference(K key, Collection<K> otherKeys) {
        return setOps.difference(key, otherKeys);
    }


    public Set<V> difference(K key, K otherKey) {
        return setOps.difference(key, otherKey);
    }


    public Set<V> intersect(K key, Collection<K> otherKeys) {
        return setOps.intersect(key, otherKeys);
    }


    public Set<V> intersect(K key, K otherKey) {
        return setOps.intersect(key, otherKey);
    }


    public Set<V> members(K key) {
        return setOps.members(key);
    }


    public V pop(K key) {
        return setOps.pop(key);
    }


    public List<V> randomMembers(K key, long count) {
        return setOps.randomMembers(key, count);
    }


    public Long remove(K key, Object... values) {
        return setOps.remove(key, values);
    }


    public Long size(K key) {
        return setOps.size(key);
    }


    public Set<V> union(K key, Collection<K> otherKeys) {
        return setOps.union(key, otherKeys);
    }


    public Set<V> union(K key, K otherKey) {
        return setOps.difference(key, otherKey);
    }


    public void delete(K key) {
        setOps.getOperations().delete(key);
    }


    public void delete(Collection<K> key) {
        setOps.getOperations().delete(key);

    }


    public RedisOperations<K, V> getOperations() {
        return setOps.getOperations();
    }


    public Boolean expire(K key, long timeout, TimeUnit unit) {
        return setOps.getOperations().expire(key, timeout, unit);
    }


    public Boolean expireAt(K key, Date date) {
        return setOps.getOperations().expireAt(key, date);
    }
}
